@extends('layouts.header')
@section('content')
    <article class="page-container">
        <form class="form form-horizontal" id="form" autocomplete="off" >
            @if (config('constant.is_profession_ver') && config('constant.wechat_have'))
            <div class="row cl">
                <label class="form-label col-sm-2">绑定微信：</label>
                <div class="formControls col-sm-4">
                    @if(auth('admin')->user()->open_id)
                        <a class="btn radius disabled">已绑定</a>
                        <input class="btn btn-link radius" type="button" value="解绑" onclick="unbindWechat();">
                    @else
                        <a class="btn btn-success radius" href="/{{config('constant.name_admin')}}/weChat/weChatBind">点击绑定微信</a>
                    @endif
                </div>
            </div>
            @endif

            @if (auth('admin')->user()->role_id === 50)
                {{-- 角色是注册客户 --}}
                <div class="row cl">
                    <label class="form-label col-sm-2">登录名：</label>
                    <div class="formControls col-sm-10">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->username }}" placeholder="" name="username" id="username" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">单位名称：</label>
                    <div class="formControls col-sm-10">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->client_name }}" disabled>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">单位地址：</label>
                    <div class="formControls col-sm-10">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->client_addr }}" placeholder="" name="client_addr" id="client_addr" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">联系人：</label>
                    <div class="formControls col-sm-10">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->client_contact }}" placeholder="" name="client_contact" id="client_contact" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">联系电话：</label>
                    <div class="formControls col-sm-10">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->client_tel }}" placeholder="" name="client_tel" id="client_tel" >
                    </div>
                </div>

            @else
                <div class="row cl">
                    <label class="form-label col-sm-2">登录名：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->username }}" placeholder="" name="username" id="username" >
                    </div>
                    <label class="form-label col-sm-2">真实姓名：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->realname }}" placeholder="" name="realname" id="realname" disabled>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">工号：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->num }}" placeholder="" name="num" id="num" >
                    </div>
                    <label class="form-label col-sm-2">工号密码：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->password2 }}" placeholder="" name="password2" id="password2" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">电话：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->telephone }}" placeholder="" name="telephone" id="telephone" >
                    </div>
                    <label class="form-label col-sm-2">出生日期：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" id="birth" name="birth" value="{{ auth('admin')->user()->birth }}" onfocus="WdatePicker({maxDate:'%y-%M-%d'})" class="input-text Wdate">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">所在部门：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->depa }}" placeholder="" name="depa" id="depa" >
                    </div>
                    <label class="form-label col-sm-2">职务：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->position }}" placeholder="" name="position" id="position" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">性别：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->gender == 1 ? '男':'女' }}" placeholder="" id="gender" disabled>
                    </div>
                    <label class="form-label col-sm-2">邮箱：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->email }}" placeholder="" name="email" id="email" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">账号注册日期：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->created_at }}" placeholder="" id="created_at" disabled>
                    </div>
                    <label class="form-label col-sm-2">入职日期：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" id="work_date" name="work_date" value="{{ auth('admin')->user()->work_date }}" onfocus="WdatePicker({maxDate:'%y-%M-%d'})" class="input-text Wdate">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">学历：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->edu }}" placeholder="" name="edu" id="edu" >
                    </div>
                    <label class="form-label col-sm-2">毕业院校：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->school }}" placeholder="" name="school" id="school" >
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">职称：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->zhicheng }}" placeholder="" name="zhicheng" id="zhicheng" >
                    </div>
                    <label class="form-label col-sm-2">主检人代号：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->tester_code }}" placeholder="" id="tester_code" name="tester_code">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">持证情况：</label>
                    <div class="formControls col-sm-10">
                        <textarea style="height: 45px" class="textarea" name="chizheng" id="chizheng">{{ auth('admin')->user()->chizheng }}</textarea>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">是否为主检人：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->istester ? '是':'否' }}" placeholder="" name="istester" id="istester" disabled>
                    </div>
                    <label class="form-label col-sm-2">搭档副检姓名：</label>
                    <div class="formControls col-sm-4">
                        <input type="text" class="input-text" value="{{ auth('admin')->user()->partner }}" placeholder="" id="partner" name="partner">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-sm-2">名章：</label>
                    <div class="formControls col-sm-4">
                        @php 
                            $report_sign = "/storage/images/managers/".auth('admin')->user()->realname.".png"; 
                            $exist = file_exists($report_sign);
                            $sign = 'sign';
                        @endphp
                        @uploadImg(['previewImgId'=>$sign,'name'=>$sign,'value'=>$report_sign]) @enduploadImg 
                        <img id="{{$sign}}" height="50px" src="{{$report_sign}}?time={{time()}}" alt="个人名章" class="radius" />
                    </div>
                </div>
            @endif
            @csrf
            <div class="row cl pt-20">
                <div class="col-sm-10 col-sm-offset-2">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    <input class="btn btn-danger radius ml-15" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;" onclick="layer_close();">
                </div>
            </div>
        </form>
    </article>
    <script type="text/javascript">
        $(function(){

            var index2;

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form").validate({
                rules:{
                    username:{
                        required:true,
                        notSpace:true,
                        minlength:1,
                        maxlength:10,
                        remote : '/{{config('constant.name_admin')}}/manager/usernameCheck',
                    },
                    num:{
                        isDigits:true,
                        minlength:6,
                        maxlength:6,
                        remote : '/{{config('constant.name_admin')}}/manager/numCheck',
                    },
                    password2:{
                        isDigits:true,
                        minlength:6,
                        maxlength:6,
                    },
                    chizheng:{
                        maxlength:200,
                    },
                },
                messages: {
                    username: {
                        remote: "此登录名已存在"
                    },
                    num: {
                        remote: "此工号已存在"
                    },
                },
                // onkeyup:false,
                // focusCleanup:false,
                success:"valid",
                submitHandler:function(form){
                   $(form).ajaxSubmit({
                        type: 'post',
                        url: "",//自己提交给自己可以不写url
                        //beforeSend  beforeSubmit

                        beforeSend : function () {
                            //0.4透明度 白色遮罩
                           index2 = layer.load(2,{ shade: [0.3,'#fff'] });
                        },
                        complete : function () {
                            layer.close(index2);
                        },
                        success: function(data) {
                            //判断添加结果
                            if(data != ''){
                                parent.update_username(data);//更新top部位的用户名
                                parent.layer.msg('操作成功!',{ icon: 1, time:2000 });
                                layer_close();//关闭自己
                            }else{
                                layer.msg('操作失败!', { icon: 2, time: 2000 });
                            }
                        },
                        error: function(data) {
                            ajax_error(data);
                        }
                    });
                }
            });
        });


        /*解绑微信公众号*/
        function unbindWechat(){
            var index2;

            layer.confirm('点击确定即可解绑微信',{title:'提示',icon:7},function(index){
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/manager/unbindWechat',
                    // dataType: 'json',
                    success: function(data){
                        // console.log(data);
                        if(data === '1'){
                            window.location.reload();//刷新
                            parent.layer.msg('解绑成功!',{icon:1,time:2000});
                        }else{
                            layer.msg('解绑失败!',{icon:2,time:2000});
                        }
                    },
                    error:function(data) {
                        ajax_error(data);
                    },
                    beforeSend : function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2,{ shade: [0.05,'#000'] });
                    },
                    complete : function () {
                        layer.close(index2);
                    },
                });
            });
        }

    </script>
@endsection